<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="edu.columbia.ubms.ejb.BookmarkSessionBeanRemote" %>
<%@ page import="edu.columbia.ubms.ejb.Item" %>

<%@ include file="sessionCheck.jsp"%>

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="ubms.css" media="screen" />
<script language="javaScript">
function checkBox() {
	if (document.regform.sharecheck.checked) {
		document.regform.bookmarkshare.value = "Y";
	} else {
		document.regform.bookmarkshare.value = "N";
	}
}
</script>
</head>
<body>
<%
int userId = (Integer)session.getAttribute("userid");
int bookmarkId = Integer.parseInt((String)request.getParameter("bookmarkid"));

try {   
    Context ctx = new InitialContext();		
    BookmarkSessionBeanRemote beanRemote = (BookmarkSessionBeanRemote)ctx.lookup("BookmarkSessionBean/remote");
	Item item = beanRemote.bookmarkGet(userId, bookmarkId);
	
	String bookmarkShareCheck = "";
	if (item.getBookmarkShare() == 'Y') {
		bookmarkShareCheck = "checked";
	}
%>
<form name="regform" action="bookmarkUpdate.jsp" method="post">
	<div class="div_1">Name</div><div><input class="input_1" type="text" name="bookmarkname" value="<%=item.getBookmarkName()%>"/></div>
	<div class="div_1">URL</div><div><input class="input_1" type="text" name="bookmarkurl" value="<%=item.getBookmarkUrl()%>"/></div>
	<div class="div_1">Description</div><div><input class="input_1" type="text" name="bookmarkdescription" value="<%=item.getBookmarkDescription()%>"/></div>
	<div class="div_1">Tag</div><div><input class="input_1" type="text" name="bookmarktag" value="<%=item.getBookmarkTag()%>"/></div>
	<div class="div_1">Share</div><div><input class="input_1" type="checkbox" name="sharecheck" onClick="checkBox();" <%=bookmarkShareCheck%>/></div>
	<input type="hidden" name="bookmarkshare" value="<%=item.getBookmarkShare()%>"/>
	<input type="hidden" name="bookmarkid" value="<%=bookmarkId%>"/>
	<input type="submit" value="Update">		
</form>
<a href="bookmarkDelete.jsp?bookmarkid=<%=bookmarkId%>">Delete</a>
<%
} catch(Exception e) {
    out.println("Error:" + e.getMessage());
}	
%>
</body>
</html>